Skip to content

Avoid temporary rectangles when reading intersection ratios (#60312) - #60312

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
rubennorte:export-D134250349
Nov 26, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
rubennorte:export-D134250349

Conversation

@rubennorte

@rubennorte rubennorte commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary:

Context

IntersectionObserverEntry ratio getters construct two temporary rectangles even though they only need stored widths and heights. This adds allocation overhead when consumers process many intersection entries.

Changes

Calculate target and root ratios directly from native rectangle tuples, retaining zero-dimension handling and upper clamping. Add a saved-entry stability integration case after subsequent scrolling and use the shared target/root ratio-read benchmarks; this diff adds no benchmark code.

Compatibility

Ratios derive from stored native geometry; overriding rectangle getters no longer changes the calculated ratios. Public rectangle getters retain their existing behavior.

Benchmark results

Optimized Fantom (native + Hermes bytecode), headless Linux, same CPU affinity. The benchmark-only baseline and ratio optimization use a base containing landed scrollMargin support. Values are median CPU time per complete invocation from the current runs; setup/assertions are outside timed work, and scaling cases have 100 measured invocations. These are workload-specific measurements, not isolated profiler timings or app-wide speedups.

Benchmark Baseline CPU Current CPU CPU reduction
Read intersectionRatio 1000 times 5.105 ms 0.152 ms 97.0%
Read rnRootIntersectionRatio 1000 times 4.962 ms 0.150 ms 97.0%

These measure callback-consumer ratio reads, not notification dispatch.

Changelog:
[General][Changed] - Reduce IntersectionObserverEntry ratio-access overhead

Reviewed By: javache

Differential Revision: D134250349

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 26, 2026
@meta-codesync

meta-codesync Bot commented Nov 26, 2026

Copy link
Copy Markdown

@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D134250349.

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot changed the title Avoid temporary rectangles when reading intersection ratios Avoid temporary rectangles when reading intersection ratios (#60312) Nov 26, 2026
rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
)

Summary:

## Context

IntersectionObserverEntry ratio getters construct two temporary rectangles even though they only need stored widths and heights. This adds allocation overhead when consumers process many intersection entries.

## Changes

Calculate target and root ratios directly from native rectangle tuples, retaining zero-dimension handling and upper clamping. Add a saved-entry stability integration case after subsequent scrolling and use the shared target/root ratio-read benchmarks; this diff adds no benchmark code.

## Compatibility

Ratios derive from stored native geometry; overriding rectangle getters no longer changes the calculated ratios. Public rectangle getters retain their existing behavior.

## Benchmark results

Optimized Fantom (native + Hermes bytecode), headless Linux, same CPU affinity. The benchmark-only baseline and final stack use the same base containing landed scrollMargin support. Values are median CPU time per complete invocation from the current runs; setup/assertions are outside timed work, and scaling cases have 100 measured invocations. These are workload-specific measurements, not isolated profiler timings or app-wide speedups.

| Benchmark | Baseline CPU | Current CPU | CPU reduction |
| --- | --- | --- | --- |
| `Read intersectionRatio 1000 times` | 5.105 ms | 0.152 ms | 97.0% |
| `Read rnRootIntersectionRatio 1000 times` | 4.962 ms | 0.150 ms | 97.0% |

These measure callback-consumer ratio reads, not notification dispatch.

Changelog:
[General][Changed] - Reduce IntersectionObserverEntry ratio-access overhead

Reviewed By: javache

Differential Revision: D134250349
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 26, 2026
rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
)

Summary:

## Context

IntersectionObserverEntry ratio getters construct two temporary rectangles even though they only need stored widths and heights. This adds allocation overhead when consumers process many intersection entries.

## Changes

Calculate target and root ratios directly from native rectangle tuples, retaining zero-dimension handling and upper clamping. Add a saved-entry stability integration case after subsequent scrolling and use the shared target/root ratio-read benchmarks; this diff adds no benchmark code.

## Compatibility

Ratios derive from stored native geometry; overriding rectangle getters no longer changes the calculated ratios. Public rectangle getters retain their existing behavior.

## Benchmark results

Optimized Fantom (native + Hermes bytecode), headless Linux, same CPU affinity. The benchmark-only baseline and final stack use the same base containing landed scrollMargin support. Values are median CPU time per complete invocation from the current runs; setup/assertions are outside timed work, and scaling cases have 100 measured invocations. These are workload-specific measurements, not isolated profiler timings or app-wide speedups.

| Benchmark | Baseline CPU | Current CPU | CPU reduction |
| --- | --- | --- | --- |
| `Read intersectionRatio 1000 times` | 5.105 ms | 0.152 ms | 97.0% |
| `Read rnRootIntersectionRatio 1000 times` | 4.962 ms | 0.150 ms | 97.0% |

These measure callback-consumer ratio reads, not notification dispatch.

Changelog:
[General][Changed] - Reduce IntersectionObserverEntry ratio-access overhead

Reviewed By: javache

Differential Revision: D134250349
rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
)

Summary:

## Context

IntersectionObserverEntry ratio getters construct two temporary rectangles even though they only need stored widths and heights. This adds allocation overhead when consumers process many intersection entries.

## Changes

Calculate target and root ratios directly from native rectangle tuples, retaining zero-dimension handling and upper clamping. Add a saved-entry stability integration case after subsequent scrolling and use the shared target/root ratio-read benchmarks; this diff adds no benchmark code.

## Compatibility

Ratios derive from stored native geometry; overriding rectangle getters no longer changes the calculated ratios. Public rectangle getters retain their existing behavior.

## Benchmark results

Optimized Fantom (native + Hermes bytecode), headless Linux, same CPU affinity. The benchmark-only baseline and final stack use the same base containing landed scrollMargin support. Values are median CPU time per complete invocation from the current runs; setup/assertions are outside timed work, and scaling cases have 100 measured invocations. These are workload-specific measurements, not isolated profiler timings or app-wide speedups.

| Benchmark | Baseline CPU | Current CPU | CPU reduction |
| --- | --- | --- | --- |
| `Read intersectionRatio 1000 times` | 5.105 ms | 0.152 ms | 97.0% |
| `Read rnRootIntersectionRatio 1000 times` | 4.962 ms | 0.150 ms | 97.0% |

These measure callback-consumer ratio reads, not notification dispatch.

Changelog:
[General][Changed] - Reduce IntersectionObserverEntry ratio-access overhead

Reviewed By: javache

Differential Revision: D134250349
)

Summary:

## Context

IntersectionObserverEntry ratio getters construct two temporary rectangles even though they only need stored widths and heights. This adds allocation overhead when consumers process many intersection entries.

## Changes

Calculate target and root ratios directly from native rectangle tuples, retaining zero-dimension handling and upper clamping. Add a saved-entry stability integration case after subsequent scrolling and use the shared target/root ratio-read benchmarks; this diff adds no benchmark code.

## Compatibility

Ratios derive from stored native geometry; overriding rectangle getters no longer changes the calculated ratios. Public rectangle getters retain their existing behavior.

## Benchmark results

Optimized Fantom (native + Hermes bytecode), headless Linux, same CPU affinity. The benchmark-only baseline and ratio optimization use a base containing landed scrollMargin support. Values are median CPU time per complete invocation from the current runs; setup/assertions are outside timed work, and scaling cases have 100 measured invocations. These are workload-specific measurements, not isolated profiler timings or app-wide speedups.

| Benchmark | Baseline CPU | Current CPU | CPU reduction |
| --- | --- | --- | --- |
| `Read intersectionRatio 1000 times` | 5.105 ms | 0.152 ms | 97.0% |
| `Read rnRootIntersectionRatio 1000 times` | 4.962 ms | 0.150 ms | 97.0% |

These measure callback-consumer ratio reads, not notification dispatch.

Changelog:
[General][Changed] - Reduce IntersectionObserverEntry ratio-access overhead

Reviewed By: javache

Differential Revision: D134250349
@meta-codesync
meta-codesync Bot merged commit 521d556 into react:main Nov 26, 2026
101 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @rubennorte in 521d556

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants